package FanXingDemon;

import java.util.*;

//示例：根据人的名字，查询这个人的全部信息。
public class Test {
    //用Map中的key和value
    public static void main(String[] args) {
        Map<String, Person> names = new HashMap<>() ;
        Person p1=new Person("zs",11,"sh");
        Person p2=new Person("ls",17,"sz");
        Person p3=new Person("ws",21,"bj");
        Person p4=new Person("zl",19,"st");
        names.put("zs",p1);
        names.put("ls",p2);
        names.put("ww",p3);
        names.put("zl",p4);
        Scanner input=new Scanner(System.in);
        String name = input.next();

     /*   Set<String>  name1= names.keySet();
        for(Object o :name1)
        {
            if(o.equals(name))
            {
                Person person= names.get(name);
                System.out.println(person);
            }
        }
*/
//如果不是null,在打印时会调用toString；如果是null，则不调用。
// 写了toString方法输出对象他会自动调用toString,还有如果找不到名字返回null
 Person person = names.get(name);//返回的类型是value的类型
        System.out.println(person);




    }
}